package com.erpanderp.wam.ac.model.service.project;

import java.util.List;

import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;

import com.erpanderp.wam.ac.model.entity.project.VISA;
import com.erpanderp.wam.util.HibernateUtil;

public class VisaDAO {
	public List<VISA> getVisaDetailsByProjectAssignmentId(Long projectAssignmentId) {
		System.out.println("IN GETPROJECT ASSIGNMENAT........");
		System.out.println("projectAssignmentId...."+projectAssignmentId);
		
		List<VISA> visaDetails = null;
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.setFlushMode(FlushMode.AUTO);
			String queryString = "from VISA v where v.projectAssignment.projectAssignmentId =:projectAssignmentId";
			System.out.println("QUERY "+queryString);
			Query query = session.createQuery(queryString).setLong("projectAssignmentId", projectAssignmentId);
			visaDetails =query.list();
			System.out.println("VISA LIST "+visaDetails.size());
			session.getTransaction().commit();

		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return visaDetails;
	}

}
